<?php

/**
 * This is the model class for table "party_party".
 *
 * The followings are the available columns in table 'party_party':
 * @property integer $id
 * @property string $create_date
 * @property string $write_date
 * @property integer $create_uid
 * @property integer $write_uid
 * @property string $code
 * @property string $vat_number
 * @property integer $code_length
 * @property string $vat_country
 * @property boolean $active
 * @property integer $lang
 * @property string $name
 * @property boolean $is_doctor
 * @property string $insurance_company_type
 * @property integer $internal_user
 * @property string $activation_date
 * @property boolean $is_patient
 * @property boolean $is_insurance_company
 * @property string $ref
 * @property string $lastname
 * @property boolean $is_institution
 * @property boolean $is_pharmacy
 * @property string $alias
 * @property boolean $is_person
 *
 * The followings are the available model relations:
 * @property PartyAddress[] $partyAddresses
 * @property PartyAddress[] $partyAddresses1
 * @property GnuhealthFamilyMember[] $gnuhealthFamilyMembers
 * @property ResUser $createU
 * @property ResUser $internalUser
 * @property ResUser $writeU
 * @property PartyCategoryRel[] $partyCategoryRels
 * @property GnuhealthPhysician[] $gnuhealthPhysicians
 * @property GnuhealthPhysician[] $gnuhealthPhysicians1
 * @property GnuhealthPatient[] $gnuhealthPatients
 * @property GnuhealthHospitalWard[] $gnuhealthHospitalWards
 */
class PartyParty extends CActiveRecord
{
	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'party_party';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('name', 'required'),
			array('create_uid, write_uid, code_length, lang, internal_user', 'numerical', 'integerOnly'=>true),
			array('create_date, write_date', 'length', 'max'=>20),
			array('vat_number, vat_country, active, is_doctor, insurance_company_type, activation_date, is_patient, is_insurance_company, ref, lastname, is_institution, is_pharmacy, alias, is_person', 'safe'),
			// The following rule is used by search().
			// @todo Please remove those attributes that should not be searched.
			array('id, create_date, write_date, create_uid, write_uid, code, vat_number, code_length, vat_country, active, lang, name, is_doctor, insurance_company_type, internal_user, activation_date, is_patient, is_insurance_company, ref, lastname, is_institution, is_pharmacy, alias, is_person', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'partyAddresses' => array(self::HAS_MANY, 'PartyAddress', 'party'),
			'partyAddresses1' => array(self::HAS_MANY, 'PartyAddress', 'relative_id'),
			'gnuhealthFamilyMembers' => array(self::HAS_MANY, 'GnuhealthFamilyMember', 'party'),
			'createU' => array(self::BELONGS_TO, 'ResUser', 'create_uid'),
			'internalUser' => array(self::BELONGS_TO, 'ResUser', 'internal_user'),
			'writeU' => array(self::BELONGS_TO, 'ResUser', 'write_uid'),
			'partyCategoryRels' => array(self::HAS_MANY, 'PartyCategoryRel', 'party'),
			'gnuhealthPhysicians' => array(self::HAS_MANY, 'GnuhealthPhysician', 'institution'),
			'gnuhealthPhysicians1' => array(self::HAS_MANY, 'GnuhealthPhysician', 'name'),
			'gnuhealthPatients' => array(self::HAS_MANY, 'GnuhealthPatient', 'name'),
			'gnuhealthHospitalWards' => array(self::HAS_MANY, 'GnuhealthHospitalWard', 'institution'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'create_date' => 'Create Date',
			'write_date' => 'Write Date',
			'create_uid' => 'Create Uid',
			'write_uid' => 'Write Uid',
			'code' => 'Code',
			'vat_number' => 'Vat Number',
			'code_length' => 'Code Length',
			'vat_country' => 'Vat Country',
			'active' => 'Active',
			'lang' => 'Lang',
			'name' => 'Name',
			'is_doctor' => 'Is Doctor',
			'insurance_company_type' => 'Insurance Company Type',
			'internal_user' => 'Internal User',
			'activation_date' => 'Activation Date',
			'is_patient' => 'Is Patient',
			'is_insurance_company' => 'Is Insurance Company',
			'ref' => 'Ref',
			'lastname' => 'Lastname',
			'is_institution' => 'Is Institution',
			'is_pharmacy' => 'Is Pharmacy',
			'alias' => 'Alias',
			'is_person' => 'Is Person',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 *
	 * Typical usecase:
	 * - Initialize the model fields with values from filter form.
	 * - Execute this method to get CActiveDataProvider instance which will filter
	 * models according to data in model fields.
	 * - Pass data provider to CGridView, CListView or any similar widget.
	 *
	 * @return CActiveDataProvider the data provider that can return the models
	 * based on the search/filter conditions.
	 */
	public function search()
	{
		// @todo Please modify the following code to remove attributes that should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('create_date',$this->create_date,true);
		$criteria->compare('write_date',$this->write_date,true);
		$criteria->compare('create_uid',$this->create_uid);
		$criteria->compare('write_uid',$this->write_uid);
		$criteria->compare('code',$this->code,true);
		$criteria->compare('vat_number',$this->vat_number,true);
		$criteria->compare('code_length',$this->code_length);
		$criteria->compare('vat_country',$this->vat_country,true);
		$criteria->compare('active',$this->active);
		$criteria->compare('lang',$this->lang);
		$criteria->compare('name',$this->name,true);
		$criteria->compare('is_doctor',$this->is_doctor);
		$criteria->compare('insurance_company_type',$this->insurance_company_type,true);
		$criteria->compare('internal_user',$this->internal_user);
		$criteria->compare('activation_date',$this->activation_date,true);
		$criteria->compare('is_patient',$this->is_patient);
		$criteria->compare('is_insurance_company',$this->is_insurance_company);
		$criteria->compare('ref',$this->ref,true);
		$criteria->compare('lastname',$this->lastname,true);
		$criteria->compare('is_institution',$this->is_institution);
		$criteria->compare('is_pharmacy',$this->is_pharmacy);
		$criteria->compare('alias',$this->alias,true);
		$criteria->compare('is_person',$this->is_person);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}

	/**
	 * Returns the static model of the specified AR class.
	 * Please note that you should have this exact method in all your CActiveRecord descendants!
	 * @param string $className active record class name.
	 * @return PartyParty the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}
}
